import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { CustomerListComponent } from './customer-list/customer-list.component';
import { CustomerAddComponent } from './customer-add/customer-add.component';
import { CustomerDetailComponent } from './customer-detail/customer-detail.component';
import { EmptyComponent } from './empty.component';
import { getNgRoute } from '@ds/ds-micro/dist';
import { isMicro } from '@ds/ds-micro-lib/dist';

const routes: Routes = [
  {
    path: '',
    component: CustomerListComponent,
  },
  {
    path: 'list',
    component: CustomerListComponent,
  },
  {
    path: 'add',
    component: CustomerAddComponent,
  },
  {
    path: 'detail',
    component: CustomerDetailComponent,
  },
  {
    path: 'detail',
    component: CustomerDetailComponent,
    children: [
      {
        path: 'list',
        component: EmptyComponent,
      },
    ],
  },
  {
    path: 'crm',
    loadChildren: () => import('./sell-crm/sell-crm.module').then(v => v.SellCrmModule),
  },
];

// 可做子应用界面
const data = {
  CustomerListComponent,
  CustomerAddComponent,
  CustomerDetailComponent,
  SellCrmModule: () =>
    import('./sell-crm/sell-crm.module').then(v => {
      console.log('懒加载滴滴撒谎略略略');
      return v.SellCrmModule;
    }),
  __empty: EmptyComponent,
};

@NgModule({
  imports: [RouterModule.forRoot(!isMicro ? routes : getNgRoute('customer', data))],
  exports: [RouterModule],
  providers: [
    // {
    //     provide: APP_BASE_HREF,
    //     // @ts-ignore
    //     // useValue: window.__MICRO_APP_BASE_ROUTE__ ||  window.__POWERED_BY_QIANKUN__ ? '/customer' : '/',
    //     useValue: window.__MICRO_APP_BASE_ROUTE__ ||  window.__POWERED_BY_QIANKUN__ ? '/' : '/',
    //   },
  ],
})
export class AppRoutingModule {}
